package com.cracker.websocket.server.controller;

import com.cracker.websocket.server.dto.BaseDto;
import com.cracker.websocket.server.dto.StatInfoDto;
import com.cracker.websocket.server.service.GmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
public class GmController {
    @Autowired
    private GmService gmService;

    @DeleteMapping("/gm/kickOut/{id}")
    public BaseDto kickOut(@PathVariable int id) throws IOException {
        gmService.kickOut(id);
        return new BaseDto<>();
    }

    @PostMapping("/gm/chatRoom/broadcast")
    public BaseDto chatRoomBroadcast(@RequestParam(name = "msg") String msg, @RequestParam(name = "roomId") String roomId) {
        gmService.chatRoomBroadcast(msg, roomId);
        return new BaseDto<>();
    }

    @PostMapping("/gm/group/broadcast")
    public BaseDto groupBroadcast(@RequestParam(name = "msg") String msg, @RequestParam(name = "groupId") String groupId) throws IOException {
        gmService.groupBroadcast(msg, groupId);
        return new BaseDto<>();
    }

    @PostMapping("/gm/sendMsg/{id}")
    public BaseDto sendMsg(@PathVariable(name = "id") int id, @RequestParam(name = "msg") String msg) throws IOException {
        gmService.sendMsg(id, msg);
        return new BaseDto<>();
    }

    @GetMapping("/gm/onlineStat")
    public BaseDto<StatInfoDto> sendMsg() {
        BaseDto<StatInfoDto> dto = new BaseDto<>();
        dto.setData(gmService.getOnlineInfo());
        return dto;
    }


}
